$(function(){
    var lastSelection;
    
    var ExamesSel;
    var numNumExame =0;
    var KitExame;
    
    var idtempSol = $("#idTempSol").val();
    
    var kitsorologia = 
        $.ajax({
            url: 'intranet/rotina/kitsorologia',
            datatype: "json",
            async: false,
            success: function(resultado){
                if (!resultado)
                    alert('Não foi possível carregar os kits sorológicos');
                }
                
        }).responseText;
    
       
       
	//Ativando a grid e setando as propriedades
	jQuery("#gridExame").jqGrid({
		caption: "", //Titulo da Grid
		url: "intranet/Rotina/getexames", //Url da requisi��o ajax para retornar os dados
                editurl:"intranet/Rotina/editexametemp/idtemp/"+idtempSol,
		datatype: "json", //Tipo de dado retornado pela requisi��o
		colNames:['id','Exame', 'Obrig.','Metodologia','Kit Sorológico'], //Titulo das colunas
		colModel:[
			//Defini��o dos par�metros para os campos da grid
			{name:'idExame', index:'idExame', width:50, align:"center"},
			{name:'nomeLongo', index:'nomeLongo', width:180, align:"left"},
                        {name:'eObrigatorio', index:'eObrigatorio', width:50, align:"center"},
                        {name:'metodologia', index:'metodologia', width:200, align:"left"},
                        {name:'kitsorologia', index:'kitsorologia', width:390, align:"left", search:false,
                                 edittype:'select', editable:true, editrules:{required:true}}
		],
                loadComplete: function(){
                          $('#gridExame').setColProp('kitsorologia', {editoptions: {value: kitsorologia}});
                         
                },
                onSelectRow: function(id){
                    if(id && id!=lastSelection){
                        var grid = $(this);
                        grid.restoreRow(lastSelection);
                        grid.editRow(id,true);
                        lastSelection=id;
                        ExamesSel = jQuery("#gridExame").getGridParam('selarrrow');
                        $('#ExameSel').val(ExamesSel);
                        
                        numNumExame = ExamesSel.length;
                        $('#qtdExameSel').val(numNumExame);
                       //var amount = document.getElementById(id+'_kitsorologia').value;
                       // alert(amount);
                            
                    }
                    
                   
                },
                
               
		width: "100%",  
		height: "100%", 
		pager: '#navExame',  
		sortname: "eObrigatorio",  
		sortorder: "DESC",  
		multiselect: true,  
                scroll:true,
		viewrecords: false,  
                subGrid: false
		}).navGrid("#navExame",{
		
		edit: false, 
		add: false, 
		del: false, 
		search: false, 
		view: false,
		refresh: true 
	});
     
});
jQuery("#gridExame").jqGrid('navGrid','#navExame',{edit:false,add:false,del:false});



